import { fileURLToPath, URL } from 'node:url'

import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'

import { viteMockServe } from 'vite-plugin-mock'

export const VITE_PORT = 3000
export const API_TARGET_URL = 'https://www.fastmock.site/mock/277ab6b09d239407261b899d472aece8'
export const MOCK_API_TARGET_URL = 'http://localhost:3000'

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [
    vue(),
    viteMockServe({
      // 存储 mock文件 的文件夹地址
      mockPath: './mock',
    }),
  ],
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url)),
    },
  },
  server: {
    port: VITE_PORT,
    proxy: {
      // 线上mock接口
      '/api': {
        target: API_TARGET_URL,
        changeOrigin: true,
      },
      // 本地mock模拟接口
      '/api/mockjs': {
        target: MOCK_API_TARGET_URL,
        changeOrigin: true,
      },
    },
  },
})
